<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>Aloha Editor contenthandler Test Suite</title>
	<!-- include qunit -->
	<link rel="stylesheet" href="../vendor/qunit.css" type="text/css"/>

	<script type="text/javascript" src="../vendor/qunit.js"></script>

	<!-- include jquery -->
	<script	src="../../lib/vendor/jquery-1.7.2.js" ></script>
	<script type="text/javascript" src="../vendor/jquery.simulate.js"></script>

	<!-- include aloha -->
	<script>
		var Aloha = {
			settings: {
				jQuery: $,
				baseUrl: '../../lib'
			}
		};
	</script>
	<script src="../../lib/require.js"></script>
	<script src="../../lib/aloha.js" data-aloha-plugins="common/commands,common/paste,common/contenthandler"></script>

	<!-- inject into testswarm -->
	<script type="text/javascript" src="../vendor/swarminject.js"></script>
	<script>
		// define realtive baseUrl path to requireJS
		// and paths back to aloha path
		require( [ 'commandtest' ] );
		//require( [ 'contenthandlertest' ] );
	</script>
</head>
<body>
	<!-- include the tests -->
	<script>
	var files, elements,
		tests = {
			defaultValue: 'bam',
			defaultCommand: 'inserthtml',
			tests: [		        
					{  	start: '[]foo',
						execResult: 'bam[]foo',
				 		value: 'bam'
				    },
					{  	start: '<p>foo[bar]baz</p>',
				       	execResult: '<p>foo</p><hr><p>[]baz</p>',
				       	value: '<hr>' 
					},
					{  	start: '<h1>foo[bar]baz</h1>',
					  	execResult: '<h1>foo</h1><h2>bam</h2><h1>[]baz</h1>',
				       	value: '<h2>bam</h2>' 
					},
					{	start: '<table><tr><td>foo[]</td></tr></table>',
						execResult: '<table><tr><td>foobam[]</td></tr></table>',
						value: 'bam' 
					},
					{	start: '<h1>hello</h1><p>bar[]</p><table><tr><td>foo</td></tr></table>',
						execResult: '<h1>hello</h1><p>barbam[]</p><table><tr><td>foo</td></tr></table>',
						value: 'bam' 
					},
					{	start: '<h1>hello</h1><p>bar[]</p>',
						execResult: '<h1>hello</h1><p>bar</p><table><tr><td>foo</td></tr></table>{}',
						value: '<table><tr><td>foo</td></tr></table>' 
					},
					{	start: 'foo[]bar',
						execResult: 'foo<div>bam</div>[]bar',
						value: '<div style="background-color:red">bam</div>'
					},
					{	start: 'foo[]bar',
						execResult: 'foo<div contentEditable="false" style="background-color:red">bam</div>[]bar',
						value: '<div contentEditable="false" style="background-color:red">bam</div>'
					}
			]
	}

	// now add tests for copy & paste from different sources (from './inserthtml/<name>-[start|expected|value].html' files)
	files = [ 'html', 'rte', 'txt', ]; // 'example-doc'
	elements = [ 'div', 'p' ];

	for ( i=0; i<files.length; i++ ) {
		var data_start, 
			data_expected,
			data_value,
			file_expected,
			index;

		file = files[ i ];

		if (Aloha.settings.sanitize) {
			file_expected = file + '-' + Aloha.settings.sanitize;
		} else {
			file_expected = file;
		}

		jQuery.ajax( {url: 'contenthandler/' + file +'-start.html', async: false, success: function(data) { 
				data_start = data;
		}} );

		jQuery.ajax( {url: 'contenthandler/' + file +'-expected.html', async: false, success: function(data) { 
				data_expected = data;
		}} );

		jQuery.ajax( {url: 'contenthandler/' + file +'-value.html', async: false, success: function(data) { 
				data_value = data;
		}} );

		/*for ( j=0; j<elements.length; j++ ) {
			tests.tests.push({
				start: '<' + elements[ j ] + '>' + data_start + '</' + elements[ j ] + '>',
				expected: '<' + elements[ j ] + '>' + data_expected + '</' + elements[ j ] + '>',
				value: data_value
			});
		}*/
		
		
		/*tests.tests.push({
			start: data_start,
			execResult: data_expected,
			value: data_value
		});*/
		
		
	};

	</script>
	<h1 id="qunit-header">Aloha Editor Paste Test Suite</h1>
	<h2 id="qunit-banner"></h2>
	<div id="qunit-testrunner-toolbar"></div>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests"></ol>
	<div id="qunit-fixture"></div>
	<div id="edit" style="margin:20px; border:1px solid #000000;"></div>
	<div id="logBody"></div>
	</div>
</body>
</html>
